#include "../vector.hpp"
#include "../matrix.hpp"
//-test-class-matrix---------------------------------------
//---------------------------------------------------------
int main(){
  printf("tests of class matrix are going to be written in 'class_matrix.txt'\n");
  FILE *fi;
  fi = fopen("class_matrix.txt","w+");
  fprintf(fi,"TEST: class matrix\n");
//---------------------------------------------------------
  fprintf(fi,"--operation: create matrixes of 0 and 4 dim:\n");
  matrixes Q, R(4);
  fprintf(fi,"R = \n");
  print_matrix(R,fi);
  fprintf(fi,"Q = \n");
  print_matrix(Q,fi);
//---------------------------------------------------------
  fprintf(fi,"--operation: matrix = matrix\n");
  Q = R;
  fprintf(fi,"Q = R = \n");
  print_matrix(Q,fi);
//---------------------------------------------------------
  fprintf(fi,"--operation: matrix * vector\n");
  vector e(4), w;
  for(size_t i=0; i<4; i++){
    e[i] = 2;
    for(size_t j=0; j<4; j++)
      R[i][j] = i;
  }
  fprintf(fi,"vector e = \n");
  print(e,fi);
  fprintf(fi,"matrix R = \n");
  print_matrix(R,fi);
  fprintf(fi,"Q = R * e =\n");
  Q = R*e;
  print_matrix(Q,fi);
//---------------------------------------------------------
  fprintf(fi,"--operation: vector * matrix\n");
  w = e*R;    
  fprintf(fi,"vector e = \n");
  print(e,fi);
  fprintf(fi,"R = \n");
  print_matrix(R,fi);
  fprintf(fi,"w = e * R =\n");
  print(w,fi);
//---------------------------------------------------------
  fprintf(fi,"--operation: matrix^-1\n");
  int n = 4;
  Q[0][0] = 1;
  Q[n-1][n-1] = 1;
  vector T(n);
  for(int i=1; i<n-1; i++){
    Q[i][i-1] = T[i+1];
    Q[i][i]   = 2*(T[i]+T[i+1]);
    Q[i][i+1] = T[i];
  }
  fprintf(fi,"Q = \n");
  print_matrix(Q,fi);
  fprintf(fi,"Q^-1 = \n");
  Q = inv_matrix(Q);
  print_matrix(Q,fi);
//---------------------------------------------------------
  fprintf(fi,"--operation: matrix * matrix\n");
  for(size_t i=0; i<4; i++)
    for(size_t j=0; j<4; j++){
      Q[i][j] = i;
      R[i][j] = j;
    }
  fprintf(fi,"R = \n");
  print_matrix(R,fi);
  fprintf(fi,"Q = \n");
  print_matrix(Q,fi);
  Q = Q*R;
  fprintf(fi,"Q * R= \n");
  print_matrix(Q,fi); 
//---------------------------------------------------------
  fclose(fi);
  return 0;
}
